package org.yzz.base.util;

import lombok.Data;
import org.yzz.base.exception.ResponseCode;

@Data
public class AjaxResult {
    private Integer code;   // 响应码
    private Object ajaxObj;
    private Boolean success;
    private String msg;


    /**
     * 正常返回，无传入对象时
     * @return
     */
    public static AjaxResult success(){
        AjaxResult result = new AjaxResult();
        result.success=true;
        result.msg=ResponseCode.RESPONSE_CODE_200.getMessage();
        result.code= ResponseCode.RESPONSE_CODE_200.getCode();
        return result;
    }
    /**
     * 正常返回，有传入对象时
     */
    public static AjaxResult success(Object obj){
        AjaxResult result = new AjaxResult();
        result.ajaxObj=obj;
        result.success=true;
        result.msg=ResponseCode.RESPONSE_CODE_200.getMessage();
        result.code=ResponseCode.RESPONSE_CODE_200.getCode();
        return result;
    }

    /**
     * 错误返回，无传入对象时
     * @return
     */
    public static AjaxResult error(){
        AjaxResult result = new AjaxResult();
        result.success=false;
        result.msg="操作失败!";
        return result;
    }

    /**
     * 错误返回，有传入对象时
     */
    public static AjaxResult error(String e){
        AjaxResult result = new AjaxResult();
        result.ajaxObj=e;
        result.success=false;
        result.msg=e;
        return result;
    }

    /**
     * 错误返回，有传入对象时
     */
    public static AjaxResult error(String e,Integer code){
        AjaxResult result = new AjaxResult();
        result.ajaxObj=e;
        result.success=false;
        result.msg=e;
        result.code=code;
        return result;
    }


}

